#! /bin/bash
# $Id: configure-universalDarwin,v 1.2 2010/01/27 00:41:28 mp Exp $

# run configure (or ../configure) for universalDarwinNN
# NN=8,9,10 (Tiger, Leopard, Snow Leopard)


osrev=$(uname -r)  # example 9.8.0 is Darwin 9.8 or Mac OS 10.9.8
ver=${osrev%%.*}  # example 9 is Darwin 9

if [ -x configure ]; then
	config=configure
elif [ -x ../configure ]; then
	config=../configure
else
	echo $0 cannot find configure script
	exit 1
fi

case $ver in
  *8) 
	# Tiger (Intel/PPC; only 32-bit is supported here)
	archlist="-arch i386 -arch ppc"
	sdkver=4u
	;;
  *9) 
	# Leopard (Intel/PPC; 32/64-bit)
	archlist="-arch i386 -arch x86_64 -arch ppc -arch ppc64"
	sdkver=5
	;;
  *10) 
	# Snow Leopard (Intel 32/64-bit)
	archlist="-arch i386 -arch x86_64"
	sdkver=6
	;;
  *)
  	echo $0 unrecogized Darwin version $ver \( osrev = $osrev \)
	exit 1
	;;
esac

configopts="--disable-dependency-tracking"

rootdir=/Developer/SDKs/MacOSX10.$sdkver.sdk

if [ ! -d $rootdir ]; then
	echo Cannot find developer tool directory $rootdir
	echo "Please download \"Developer Tools\" from apple.com."
	exit 1
fi

echo running env CXXFLAGS="-O3 -isysroot $rootdir $archlist" \
    LDFLAGS="$archlist" \
    $config $configopts

env CXXFLAGS="-O3 -isysroot $rootdir $archlist" \
    LDFLAGS="$archlist" \
    $config $configopts

